package com.yhd.task.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhd.task.model.Task;
import com.yhd.task.model.TaskVO;
import com.yhd.task.service.TaskService;
import com.yhd.task.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 任务接口
 *
 * @author yinhuidong3@xiaomi.com
 * @since 2021/7/4
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    @PostMapping("task")
    public Result addTask(  TaskVO taskVO){
        taskService.addTask(taskVO);
        return Result.SUCCESS();
    }

    @DeleteMapping("task/{id}")
    public Result deleteTask(@PathVariable("id") Integer id){
        taskService.deleteTask(id);
        return Result.SUCCESS();
    }

    @PutMapping("task}")
    public Result putTask(TaskVO taskVO){
        taskService.updateTask(taskVO);
        return Result.SUCCESS();
    }

    @GetMapping("page/{page}/{size}")
    public Result<IPage<Task>> pageTask(@PathVariable("page")Integer page,@PathVariable("size")Integer size){
        return Result.SUCCESS(taskService.pageTask(page,size));
    }

    @PostMapping("task/{id}")
    public Result startTask(@PathVariable("id") Integer id){
        taskService.startTask(id);
        return Result.SUCCESS();
    }
    @DeleteMapping("endtask/{id}")
    public Result endTask(@PathVariable("id") Integer id){
        taskService.stopTask(id);
        return Result.SUCCESS();
    }

    @PostMapping("test")
    public Result test(){
        System.out.println("测试任务生成！");
        return Result.SUCCESS();
    }
}
